<!DOCTYPE html>
<html>
<html>

<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
	<style type="text/css">
		@import url(./../lib/Cesium/Widgets/widgets.css);

		body,
		html,
		#map {
			width: 100%;
			height: 100%;
			overflow: hidden;
			margin: 0;
			font-family: "微软雅黑";
		}
	</style>

	<script src="./../lib/Cesium/Cesium.js"></script>
	<title>防止地形穿透</title>
</head>

<body onload="onload()">
	<div id="map"></div>
</body>

</html>
<script type="text/javascript">
Cesium.Ion.defaultAccessToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiI5NTFhMDMwMi02YWVjLTRmNmItOThjNS00MDI1YTVkNjdhODciLCJpZCI6NTY0Miwic2NvcGVzIjpbImFzciIsImdjIl0sImlhdCI6MTU0MzgyNzA5MH0.4OIh4gPgWSceyKB4iHliAX59933ryNrXBwVut46WE78'
	function onload() {
		const viewer = new Cesium.Viewer("map", {
			animation: false, //是否创建动画小器件，左下角仪表
			baseLayerPicker: false, //是否显示图层选择器
			fullscreenButton: false, //是否显示全屏按钮
			geocoder: false, //是否显示geocoder小器件，右上角查询按钮
			homeButton: false, //是否显示Home按钮
			infoBox: false, //是否显示信息框
			sceneModePicker: false, //是否显示3D/2D选择器
			selectionIndicator: false, //是否显示选取指示器组件
			timeline: false, //是否显示时间轴
			sceneMode: Cesium.SceneMode.SCENE3D, //设定3维地图的默认场景模式:Cesium.SceneMode.SCENE2D、Cesium.SceneMode.SCENE3D、Cesium.SceneMode.MORPHING
			navigationHelpButton: false, //是否显示右上角的帮助按钮
			scene3DOnly: true, //如果设置为true，则所有几何图形以3D模式绘制以节约GPU资源
			navigationInstructionsInitiallyVisible: false,
			showRenderLoopErrors: false

		})
		viewer.scene.globe.depthTestAgainstTerrain = false;
		//去除版权信息
		viewer._cesiumWidget._creditContainer.style.display = 'none';
		let scene = viewer.scene,
			camera = viewer.camera, startMousePosition, mousePosition;

		scene.screenSpaceCameraController.minimumZoomDistance = 100;
		viewer.clock.onTick.addEventListener(() => {
			if (camera.pitch > 0) {
				scene.screenSpaceCameraController.enableTilt = false;
			}
		});
		var handler = new Cesium.ScreenSpaceEventHandler(viewer.canvas);
		handler.setInputAction(function (movement) {

			mousePosition = startMousePosition = Cesium.Cartesian3.clone(movement.position);
			handler.setInputAction(function (movement) {
				mousePosition = movement.endPosition;
				var y = mousePosition.y - startMousePosition.y;

				if (y > 0) {
					scene.screenSpaceCameraController.enableTilt = true;
				}
			}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
		}, Cesium.ScreenSpaceEventType.MIDDLE_DOWN);
	}

</script>